<template>
  <div class="hospitalDepartment padding_20">
    <el-input v-model="hospitalName"
              placeholder="请输入医院名称"
              class="w-200"
              clearable
              @clear="handleQuery" />
    <el-button type="primary"
               @click="handleQuery">查 询</el-button>
    <!-- <el-button type="primary"
               @click="handleOption(null, 'add')">新 增</el-button> -->
    <element-table class="mt-20"
                   :columns="columns"
                   :data="tableData"
                   v-loading="loading"
                   pager
                   :pageTotal="pageTotal"
                   :pageIndex="pageIndex"
                   :pageSize="pageSize"
                   @handleChangePage="handleChangePage">
    </element-table>
  </div>
</template>

<script>
  import ElementTable from '@/base/ElementTable'
  export default {
    name: "hospitalDepartment",
    data () {
      return {
        loading: false,
        hospitalName: null,
        pageIndex: 1,
        pageSize: 20,
        pageTotal: 0,
        tableData: [],
        columns: [
          {
            label: '医院名称',
            prop: 'name',
            width: 500,
          }, {
            label: '医院中心名称',
            prop: 'hospitalCenterName',
          }, {
            label: '联系电话',
            prop: 'phone',
            align: 'center'
          }, {
            label: '创建时间',
            prop: 'createTime',
            align: 'center',
            width: 200,
            formatter: (row, cellValue) => {
              return this.commonFunction.timestampFormat(new Date(row.createTime), 'yyyy-MM-dd hh:mm:ss')
            }
          }, {
            label: '地址',
            prop: 'address',
          }, {
            label: '操作',
            prop: 'option',
            align: 'center',
            width: 200,
            isSlot: true,
          }
        ],
      }
    },
    created () {
      this.getList();
    },
    methods: {
      handleQuery() {
        this.pageIndex=1
        this.getList()
      },
      async getList () {
        this.loading = true;
        const { data: res } = await this.post(this.api.hospitalManager.list, {
          name: this.hospitalName,
          pageSize: this.pageSize,
          pageIndex: this.pageIndex - 1
        });
        if (res.code === '200') {
          this.loading = false;
          this.tableData = [];
          this.pageTotal = res.totalNum;
        }
      },

      // 分页
      handleChangePage (page) {
        this.pageIndex = page;
        this.getList();
      },
      handleOption (row, op) {
        switch (op) {
          case 'add':
            break;
        }
      }
    },
    components: {
      'element-table': ElementTable,
    }
  }
</script>

<style scoped>
</style>
